public class Solution1 {
    public static int countSegments(String s) {

        if (s.isEmpty()) {
            return 0;
        } else {
            String[] result = s.split(" ");
            int x = result.length;
            for (String value : result) {
                if (value.isEmpty()) {
                    x--;
                }
            }
            return x;
        }
    }

    public static void main(String[] args) {
        System.out.println(countSegments("Hello, my name is John"));
        System.out.println(countSegments("   a b"));
    }
}
